From : Alexander Wingrove (awingrove@thenet.co.uk)
Subject : Reading the currently selected item in a listview gadget
> - How can I find out which is the currently selected item that a user
> selected in a listview.
Following is the code I use to find which list item has been clicked on. If anyone knows anything better, I'd love to here.
; structure for each item on list
NEWTYPE .user
num.w ; important. must be word and must be first ( don't
; remember why though :-( )
name$
End NEWTYPE
Dim List users.user(10)
; set the num value for each item to a value corrosponding to their
; position in the list view. i.e. 0 for first item, 1 for second, etc
; these values must be recalculated if the list changes
ResetList users()
count.b=0
While AddItem( users() )
users()\num=count
Let count + 1
Wend
ev.l=WaitEvent
Select ev
Case $40
Select GadgetHit
Case #LIST_BOX_ID ; if our list box is clicked on
ResetList users()
found.b=False
Repeat
If NextItem(users())
If users()\num=EventCode ; search through \num's until
found=True ; item selected is found
EndIf
EndIf
; here, users() now points to the selected list item
Until found=True
End Select
End Select
; EventCode is the number of the item clicked on. So if EventCode was 5,
; the 5th item from the top was clicked on.